| Conditions | 10 |
| Paths | 8 |
| Total Lines | 24 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Complex classes like meta.js ➔ add often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
| 1 | import extend from 'extend' |
||
| 8 | export function add(tpl, json, type, obj = {}, date = null, realType = 'draft') { |
||
| 9 | let meta = config.meta.name |
||
| 10 | |||
| 11 | // json[meta] = extend({}, json[meta]) |
||
| 12 | var currentDate = (typeof date !== 'undefined' && date !== null && date !== '') ? date : new Date() |
||
| 13 | var abeUrl = (type === 'publish') ? json[meta].link : cmsData.fileAttr.add(json[meta].link, 'd' + dateSlug(currentDate.toISOString())) + '' |
||
| 14 | |||
| 15 | if(typeof json[meta].date === 'undefined' || json[meta].date === null) { |
||
| 16 | json[meta].date = currentDate |
||
| 17 | } |
||
| 18 | json[meta].latest = { |
||
| 19 | date: currentDate, |
||
| 20 | abeUrl: abeUrl |
||
| 21 | } |
||
| 22 | json[meta].status = realType === 'reject' ? 'draft' : realType |
||
| 23 | if(typeof json[meta][type] === 'undefined' || json[meta][type] === null) { |
||
| 24 | json[meta][type] = JSON.parse(JSON.stringify(obj)) |
||
| 25 | json[meta][type].date = currentDate |
||
| 26 | json[meta][type].abeUrl = abeUrl |
||
| 27 | } |
||
| 28 | json[meta][type].latest = JSON.parse(JSON.stringify(obj)) |
||
| 29 | json[meta][type].latest.date = currentDate |
||
| 30 | json[meta][type].latest.abeUrl = abeUrl |
||
| 31 | } |